<?php


namespace Module\DyAi\Admin\Controller;


use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;
use ModStart\Grid\GridFilter;
use ModStart\Support\Concern\HasFields;
use Module\DyAi\Util\DyAiZhuanjiUtil;
use ModStart\Form\Form;
use Module\DyAi\Model\DyAiZhuanji;
use Module\DyAi\Type\ZhuanjiStatus;

class DyAiZhuanjiController extends Controller
{
    use HasAdminQuickCRUD;

    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder
            ->init(DyAiZhuanji::class)
            ->field(function ($builder) {
                /** @var HasFields $builder */
                $builder->id('id', 'ID');
                $builder->text('sub_title', '专辑名');
                $builder->text('title', '标题');
                $builder->text('tag', '标签');
                $builder->text('keywords', '关键词')->listable(false);
                $builder->json('sub_text', '提交内容')->listable(false);
                $builder->json('dep_json', 'json内容')->listable(false);
                //$builder->text('zj_banner', '主图');
                $builder->display('created_at', L('Created At'))->listable(false);
                $builder->display('updated_at', L('Updated At'))->listable(false);
                $builder->type('status', '状态')->type(ZhuanjiStatus::class, [
                    ZhuanjiStatus::WAIT => 'danger',
                    ZhuanjiStatus::ADOPT => 'success',
                ])->required();
            })
            ->gridFilter(function (GridFilter $filter) {
                $filter->eq('id', L('ID'));
                $filter->like('sub_title', L('Title'));
                $filter->eq('status', '状态')->autoHide(false)->select(ZhuanjiStatus::class);
            })
            ->hookChanged(function (Form $form) {
                DyAiZhuanjiUtil::clearCache();
            })
            ->title('专辑列表')
            ->canSort(false)
            ->canEdit(false);
    }
}
